﻿Public Class F_MonAn
    Dim m As New DTOMonAn
    Dim action As Integer = 1
    Sub receiveData(ByVal ma As DTOMonAn, ByVal a As Integer)
        action = a
        txtTenMon.Text = ma.TenMA
        txtDongia.Text = ma.DonGia
        m.MaMA = ma.MaMA
        m.MaHang = ma.MaHang
        cbbNhomhag.SelectedValue = m.MaHang
    End Sub
    Sub loadnhomhang()
        cbbNhomhag.DataSource = DataProvider.LoadTable("select * from NHOMHANG")
        cbbNhomhag.ValueMember = "MaHang"
        cbbNhomhag.DisplayMember = "TenHang"
        cbbNhomhag.SelectedIndex = 2
    End Sub
    Private Sub F_MonAn_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        loadnhomhang()
        If action = 1 Then
            cbbNhomhag.SelectedIndex = 0
        Else
           
        End If
    End Sub
    Function checkEmpty() As Boolean
        If txtDongia.Text = "" Or txtTenMon.Text = "" Then
            Return False
        End If
        Return True
    End Function
    Sub getDataInForm()
        m.TenMA = txtTenMon.Text
        m.DonGia = txtDongia.Text
        m.MaHang = cbbNhomhag.SelectedValue
    End Sub

    Private Sub btnGhidulieu_Click(sender As Object, e As EventArgs) Handles btnGhidulieu.Click
        getDataInForm()
        If action = 0 Then
            BUSMonAn.MonAn_Update(m)
            action = 1
        Else
            If checkEmpty() = False Then
                MsgBox("Dữ liệu chưa nạp đủ !")
                Return
            End If
            BUSMonAn.MonAn_Insert(m)
        End If
        Dim u As New UC_QuanLyNhanVien
        u.loadGvNhanvien()
        Me.Close()
    End Sub
End Class